<template>
  <div class="tab-control">
    <div
      v-for="(item, index) in titles"
      class="tab-control-item"
      @click="change(index)"
      :class="{ borderbottom: index == currentindex }"
    >
      <span>{{ item }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "tab-control",
  data() {
    return {
      currentindex: 0,
    };
  },
  props: {
    titles: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  methods: {
    change(index) {
      this.currentindex = index;
      this.$emit("tabclick", index);
    },
  },
};
</script>

<style scoped>
.tab-control {
  /* 粘性布局  sticky   当超过top的值时，会变成fixed布局 */
  background-color: ghostwhite;
  /* top: 44px; */
  display: flex;
  height: 43px;
  line-height: 43px;
}
.tab-control-item {
  flex: 1;
  text-align: center;
  font-size: 14px;
}
.borderbottom {
  color: var(--color-high-text);
}
.borderbottom span {
  padding-bottom: 3px;
  border-bottom: 3px solid var(--color-tint);
}
</style>